package com.fortune.common.acl;


import com.fortune.entity.DUser;
import com.fortune.entity.MUser;

import javax.servlet.http.HttpServletRequest;

public class RequestHolder {

    private static final ThreadLocal<MUser> mUserHolder = new ThreadLocal<MUser>();
    private static final ThreadLocal<DUser> dUserHolder = new ThreadLocal<DUser>();

    private static final ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal<HttpServletRequest>();

    public static void add(DUser sysUser) {
        dUserHolder.set(sysUser);
    }

    public static void add(MUser sysUser) {
        mUserHolder.set(sysUser);
    }

    public static void add(HttpServletRequest request) {
        requestHolder.set(request);
    }

    public static MUser getMCurrentUser() {
        return mUserHolder.get();
    }

    public static DUser getDCurrentUser() {
        return dUserHolder.get();
    }

    public static HttpServletRequest getCurrentRequest() {
        return requestHolder.get();
    }

    public static void remove() {
        dUserHolder.remove();
        mUserHolder.remove();
        requestHolder.remove();
    }
}
